<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <!-- <h3>@keyup.enter  →  监听键盘回车事件</h3>
    <input v-model="username" type="text"> -->
    <input type="text" v-model="name">
    <input type="text" v-model.number="score">
    <button @click="add()">添加</button>
    <ul>
      <li v-for="(item,index) in arr" :key="item.id">
        {{item.name}}:{{item.score}} <button @click="del(index)">删除</button>
      </li>
    </ul>
    <p>平均值:{{avg}}</p>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        // username: ''
        arr: [
          { id: 1, name: '张三', score: 80 },
          { id: 2, name: '李四', score: 60 },
          { id: 3, name: '王五', score: 50 },
        ],
        score: '',
        name: ''
      },
      methods: {
        add() {
          this.arr.push({ id: Date.now(), name: this.name, score: this.score });
          this.name = this.score = ''
        },
        del(i){
          this.arr.splice(i,1)
        }
      },
      computed: {
        avg() {
          return this.arr.reduce((sum, item) => sum + item.score, 0) / this.arr.length
        }
      }
    })
  </script>
</body>

</html>